using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Nextel.Utils;
using System.Collections.Generic;


public partial class Default : System.Web.UI.Page
{
    #region Eventos
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!this.IsPostBack)
        {
            pngEmergencia.Visible = false;

            
            IdiomaCultura.datos = DBPrincipal.getCultureIdioma(IdiomaCultura.TIPO_WEB);
            
           DBPrincipal.getConfiguracion();
         
        }
            
        btnAceptar.Text = IdiomaCultura.getMensaje(IdiomaCultura.WEB_INGRESAR);
        
        txtUsuario.Focus();
    }

    protected void btnAceptar_Click(object sender, EventArgs e)
    {
        subLogin();
    }

    #endregion

    private void subLogin()
    {
        String pw = txtPassword.Text.Trim();
        String pwcrypt = FormsAuthentication.HashPasswordForStoringInConfigFile(pw, "sha1");

        UsuarioBean usuario = DBPrincipal.getLoginWeb(txtUsuario.Text, pwcrypt);
        

        if (usuario == null)
        {
            pngEmergencia.Visible = true;
            txtUsuario.Text = String.Empty;
            txtPassword.Text = String.Empty;
        }
        else
        {
            Session[SessionManager.USER_SESSION] = usuario;
            RolManager.asignarPermiso(DBUsuario.getUsuarioRolPerfil(usuario.codigoperfil));

            DBPrincipal.getSupervisor(usuario.codigo.ToString());

            string urlhome = usuario.codigorol != null  ? Request.ApplicationPath +  URLManager.getURL(usuario.codigorol) : Request.ApplicationPath + "/home.aspx";
            
            Response.Redirect(urlhome, true);
            
        }
    }
}
